#!/bin/bash 
set -e

TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage3}
SRC=${SRC:-/sources}

name=dbus
version=1.12.20

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.gz -C $TMP

{ time \
   {

    cd $TMP/$name-$version
    
	./configure --prefix=/usr                            \
	            --sysconfdir=/etc                        \
	            --localstatedir=/var                     \
	            --disable-static                         \
	            --disable-doxygen-docs                   \
	            --disable-xml-docs                       \
	            --docdir=/usr/share/doc/$name-$version \
	            --with-console-auth-dir=/run/console
    
    make
    
    make install
    
	mv -v /usr/lib/libdbus-1.so.* /lib
	ln -sfv ../../lib/$(readlink /usr/lib/libdbus-1.so) /usr/lib/libdbus-1.so

	ln -sfv /etc/machine-id /var/lib/dbus

	sed -i 's:/var/run:/run:' /lib/systemd/system/dbus.socket

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
